package com.atguigu.bigdata.spark.core.rdd.operator.transform

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

/**
  * create by undeRdoG on  2021-06-08  13:06
  * 凡心所向，素履以往，生如逆旅，一苇以航。
  */
object Spark05_RDD_Operator_Transform_Test {

  def main(args: Array[String]): Unit = {
    val sparkConf = new SparkConf().setAppName("Operator").setMaster("local[*]")
    val sc = new SparkContext(sparkConf)

    /**
    *  生成两个分区的rdd
    * */
    val rdd: RDD[Int] = sc.makeRDD(List(1,2,3,4),2)

   /**
   *  获取分区内的最大值求和
   * */
    val glomRDD: RDD[Array[Int]] = rdd.glom()

    val res: RDD[Int] = glomRDD.map(arr => {
      arr.max
    })

    val sum: Int = res.collect().sum
    println(sum)
    sc.stop()
  }
}
